﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using LotteryAdmin.AdminService;
namespace LotteryAdmin
{
    public partial class ChangeBonus : ChildWindow
    {
        PlayTypeRadioInfo PtInfo;
        PlayTypeRadioInfo OriginalData;
        private LotteryAdminClient srv;
        public ChangeBonus()
        {
            InitializeComponent();
            srv = WcfProxy.GetProxy;
            srv.UpdatePlayTypeRadioBonusCompleted += new EventHandler<UpdatePlayTypeRadioBonusCompletedEventArgs>(srv_UpdatePlayTypeRadioBonusCompleted);
        }
        public ChangeBonus(PlayTypeRadioInfo info)
            : this()
        {
            PtInfo = ModelCopy.CopyValueForModel<PlayTypeRadioInfo>(info);
            OriginalData = info;
            this.Title += ("->" + info.LotteryName + "->" + info.PlayTypeName+"->"+info.PlayTypeRadioName);
        }
        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            if (dataForm1.ValidateItem())
            {
                if (PtInfo.Multiple == 1000)
                    PtInfo.MinScale = PtInfo.BaseScale / 2;
                if (ModelCopy.ComPareModelValue<PlayTypeRadioInfo>(OriginalData, PtInfo))
                    this.DialogResult=true;
                OriginalData = ModelCopy.CopyValueForModel<PlayTypeRadioInfo>(PtInfo, OriginalData);
                srv.UpdatePlayTypeRadioBonusAsync(OriginalData);
            }
        }
        void srv_UpdatePlayTypeRadioBonusCompleted(object sender, UpdatePlayTypeRadioBonusCompletedEventArgs e)
        {
            if (e.Result)
                this.DialogResult = true;
            else
                MessageBox.Show("操作失败,网络异常或者服务器不可连接!");
        }
        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }

        private void dataForm1_Loaded(object sender, RoutedEventArgs e)
        {
            this.dataForm1.CurrentItem = PtInfo;
            if (PtInfo.Multiple==1000)
            {
                (this.dataForm1.FindNameInContent("lb_MinScale") as DataField).Visibility = Visibility.Collapsed;
                lbl_Msg.Text = "注意:该玩法是固定奖金玩法，只能修改奖金基数.";
            }
        }
    }
}

